import  random
class MuchError(Exception):
    pass
class Victory(Exception):
    pass

player = ['小黄','小黑','小白','小红']
role = ['女巫','猎人','狼人','村民','守卫','长老','预言家','白狼王']

player = random.sample(player,len(player))
role = random.sample(role,len(role))
print('游戏中全部的角色有：'+'、'.join(role))
matching={}
for t in range(len(player)):
    matching[player[t]]=role[t]

try:
    result, err = 0, 0
    for t in player:
        for i in range(2):
            guess=input('你认为'+t+'的身份是：')
            if guess == matching[t]:
                result+=1
                print('你猜对了')
                break
            else:
                err+=1
                print('你猜错了，你还有'+str(1-i)+'次机会')
        if err>5:
            raise MuchError('游戏次数已经超过5次，游戏结束')
    if result==len(player):
        raise Victory('恭喜你，全部猜对了')
except MuchError as errInfo:
    print(errInfo)








